package com.rxmvp.notifycationdemo;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class MyService extends Service {

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.e("tag", "onCreate");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        //获取交互数据
        String extra = intent.getStringExtra("notification");
        //判断action，进行不同的处理
        if ("com.huang.notification.service.delete1".equals(intent.getAction())) {
            extra = "收到了delete1 ： " + extra;
        } else if ("com.huang.notification.service.delete2".equals(intent.getAction())){
            extra = "收到了delete2 ： " + extra;
        }
        Toast.makeText(this, "service : 通知被销毁了，并打开服务，接收的数据：" + extra, Toast.LENGTH_SHORT).show();

        stopService(intent); //执行完任务，销毁自己

        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Toast.makeText(this, "服务被销毁了", Toast.LENGTH_SHORT).show();
    }
}
